package cz.data.domain.system.controller;

import cz.data.common.base.BaseController;
import cz.data.common.annotation.DataInner;
import cz.data.domain.system.model.dto.LogDto;
import cz.data.domain.system.service.LogService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.concurrent.CompletableFuture;

@Api(tags = "内部请求API", hidden = true)
@RestController
@RequestMapping("/inner")
public class InnerController extends BaseController {

    @Resource
    ThreadPoolTaskExecutor taskExecutor;
    @Autowired
    LogService logService;

    @DataInner
    @PostMapping("/logs")
    public void saveLog(@RequestBody LogDto log) {
        CompletableFuture.runAsync(() -> logService.saveLog(log), taskExecutor);
    }
}
